package com.ruoyi.yuyuan.Controller;

import com.ruoyi.yuyuan.DTO.BlogDealDTO;
import com.ruoyi.yuyuan.DTO.Result;
import com.ruoyi.yuyuan.Service.IDealBlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @Author: kestrel
 * @Version:1.0
 * @Date: 2024/5/29
 */
@RestController
@RequestMapping("/dealBlog")
public class DealBlogController {
    @Autowired
    private IDealBlogService dealBlogService;

    //发布交易贴
    @PostMapping("/publish")
    public Result publishDeal(@RequestBody BlogDealDTO blogDealDTO) throws InterruptedException {
        return dealBlogService.publishDeal(blogDealDTO);
    }

    //更新交易贴
    @PostMapping("/update/{blogId}")
    public Result updateDeal(@RequestBody BlogDealDTO blogDealDTO,@PathVariable Long blogId) throws InterruptedException {
        return dealBlogService.updateDeal(blogDealDTO, blogId);
    }

    //获取交易贴
    @GetMapping("/{blogId}")
    public Result getSingleDeal(@PathVariable Long blogId){
        return dealBlogService.getSingleDeal(blogId);
    }

    //分页查询交易贴
    @GetMapping("/page/{startId}")
    public Result getDeals(@PathVariable Long startId){
        return dealBlogService.getDeals(startId);
    }

    //搜索交易帖子
    @GetMapping("/SearchDeals/{searchKeyWord}/{type}")
    public Result getSearchDeals(@PathVariable String searchKeyWord, @PathVariable Short type) throws IOException {
        return dealBlogService.getSearchDeals(searchKeyWord, type);
    }
}
